﻿using OnlineCourse.Model;
using OnlineCourse.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineCourse.Services
{
    public class LikeCollectionService : IServices.ILikeCollectionServices
    {
        private readonly ApplicationDbContext _db;
        public LikeCollectionService(ApplicationDbContext db)
        {
            this._db = db;
        }
        /// <summary>
        /// 添加收藏
        /// </summary>
        /// <param name="CourseId"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public bool Add(Guid CourseId, Guid UserId)
        {
            try
            {
                LikeCollection model = new LikeCollection();
                model.CourseId = CourseId;
                model.UserId = UserId;
                _db.LikeCollections.Add(model);
                _db.SaveChanges();
                return true;
                
            }
            catch (Exception)
            {
                return false;
            }
        }
        /// <summary>
        /// 取消收藏
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(Guid id)
        {
            try
            {
                var m = _db.LikeCollections.FirstOrDefault(p => p.Id == id);
                _db.LikeCollections.Remove(m);
                _db.SaveChanges();
                return true;
            }
            catch (Exception err)
            {

                throw err;
            }
        }
    }
}
